package Server.Queue;

import Client.ClientCompareATime;
import Const.ServerConst;
import Server.ServerClientInstance;
import java.io.Serializable;
import java.util.Collections;
import java.util.LinkedList;

/**
 *
 * Class description goes here.
 *
 * @author Kamil Gajowy
 */
public class PersonQueueSorted extends PersonQueue implements Serializable {


    /**
    * Default constructor.
     * @param queueType typ kolejki. Typy zdefiniowane w ServerConst.
     */
    public PersonQueueSorted(int queueType){
        super(queueType);
    }

    @Override
    public boolean addPerson(ServerClientInstance client){
        if ( myType == ServerConst.QueueLimited
                && getClientList().size() >= capacity ){
            return false;
        }
        else{
            getClientList().add(client);
            return true;
        }
    }

    public void sortByArriveTime() {
        LinkedList<ServerClientInstance> list = getClientList();
        Collections.sort(list, new ClientCompareATime());
    }


}//end class
